<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<%@ include file="/pages/inc/taglibs.jsp"%>
</head>
<body style="padding-top: 50px">

	<div class="container filter">
		<input type="button" value="增加" data-target="#addmodal" data-toggle="modal" onclick="openAddEmployeeFee()"> 
		<input type="button" value="修改" onclick="openEditEmployeeFee()" data-target="#addmodal" data-toggle="modal"> <input type="button" value="删除" onclick="deleteEmployeeFee()">
		<div id="employeeFeeList">
			<table class="table table-striped table-bordered" cellspacing="0"
				width="100%">
				<thead>
					<tr>
						<th></th>
						<th>员工姓名</th>
						<th>职位</th>
						<th>部门</th>
						<th>月份</th>
						<th>工资</th>
						<th>五险一金</th>
						<th>其他费用</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<th></th>
						<th>员工姓名</th>
						<th>职位</th>
						<th>部门</th>
						<th>月份</th>
						<th>工资</th>
						<th>五险一金</th>
						<th>其他费用</th>
					</tr>
				</tfoot>
				<tbody>
					<c-rt:forEach items="${employeeFeeList}" var="employeeFee">
						<tr>
							<td><input type="checkbox" name="employeeFeeCheckbox"
								value="${employeeFee.id}"></td>
							<td><a ref="#">${employeeFee.name}</a></td>
							<td>${employeeFee.station}</td>
							<td>${employeeFee.department}</td>
							<td>${employeeFee.operDate}</td>
							<td>${employeeFee.wage}</td>
							<td>${employeeFee.welfare}</td>
							<td>${employeeFee.otherCharge}</td>
						</tr>
					</c-rt:forEach>
				</tbody>

			</table>
		</div>
	</div>
	<!-- addproject modal -->
	<div id="addmodal" class="modal fade">
		<div class="modal-dialog modal-lg">
			<div class="container newproject">
				<div class="modal-content">
					<div class="modal-header">
						<h4 class="modal-title">员工管理</h4>
					</div>
					<div class="modal-body">
						<form id="installationForm" class="form-horizontal">
							<div class="tab-content">
								<!-- First tab -->
								<div class="tab-pane active" id="basic-tab">
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal"
							onclick="saveEmployeeFee()">提交</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					</div>
				</div>

			</div>
		</div>
	</div>
	<script type="text/javascript">
		function openAddEmployeeFee() {
			$.ajax({
				url : "<c:url value='/company/employeeFee/addView' />",
				data : {},
				type : 'POST',
				dataType : 'html',
				success : function(data) {
					$("#addmodal").html("");
					$("#addmodal").html(data);
				},
				error : function(data) {
					alert("error");
				}
			});
		}
		function openEditEmployeeFee() {
			if ($('input[name="employeeFeeCheckbox"]:checked').length != 1) {
				alert("修改产品只能选择一条记录！");
				return false;
			}
			var id = $('input[name="employeeFeeCheckbox"]:checked').val();
			$.ajax({
				url : "<c:url value='/company/employeeFee/editView' />",
				data : {
					id : id
				},
				type : 'POST',
				dataType : 'html',
				success : function(data) {
					$("#addmodal").html("");
					$("#addmodal").html(data);
				},
				error : function(data) {
					alert("error");
				}
			});
		}
		function saveEmployeeFee() {
			var json = {};
			json.id = $("#employeeFeeId").val();
			json.employeeId = $("#employeeId").val();
			json.operDate = $("#operDate").val();
			json.wage = $("#wage").val();
			json.welfare = $("#welfare").val();
			json.otherCharge = $("#otherCharge").val();
			$.ajax({
				url : "<c:url value='/company/employeeFee/save' />",
				type : 'POST',
				dataType : 'json',
				data : json,
				success : function(data) {
					query();
				},
				error : function(data) {
					alert("error");
				}
			});
		}
		function deleteEmployeeFee() {
			var ids = "";
			$('input[name="employeeFeeCheckbox"]:checked').each(function() {
				ids += $(this).val() + ",";
				//alert($(this).val()); 
			});
			var json = {};
			json.ids = ids;
			$.ajax({
				url : "<c:url value='/company/employee/fee/delete' />",
				type : 'POST',
				dataType : "json",
				data : json,
				success : function(data) {
					query();
				},
				error : function(data) {
					alert("error");
				}
			});
		}

		function query() {
			$.ajax({
				url : "<c:url value='/company/employee/fee/list' />",
				data : {},
				type : 'POST',
				dataType : 'html',
				success : function(data) {
					$("#employeeFeeList").html("");
					$("#employeeFeeList").html(data);
				},
				error : function(data) {
					alert("error");
				}
			});
		}
	</script>
</body>
</html>